package com.wsjc.common.redis.sentinels;

import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;

import com.wsjc.common.core.config.JedisConfig;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

/**
 * 基于sentinel 服务版哨兵
 * 
 * @author 93733
 *
 */
public class JedisServerSentinels {

	@Autowired
	private static  JedisPoolConfig jedisPoolConfig ;
	
	private static JedisSentinelPool jedisSentinelPool ;
	
	static{
		
		Set<String> set = new HashSet<>() ;
		set.add(JedisConfig.readConfig("redis.sentinel.host1")) ;
		set.add(JedisConfig.readConfig("redis.sentinel.host2")) ;
		String masterName = JedisConfig.readConfig("redis.sentinel.master.name") ;
		String password = JedisConfig.readConfig("redis.auth.password") ;
		
		jedisSentinelPool = new JedisSentinelPool(masterName, set,jedisPoolConfig , password) ;
		
	}
	

	/**
	 * 获取jedis 实例
	 * @param sentinelMaster
	 * @return
	 */
	public static Jedis newJedisInstance() {
        return jedisSentinelPool.getResource() ;
	}

	

}
